package Pattern.SinglePattern.SingleTest;

public class Singleton {
    private static Singleton obj;

    private Singleton() {
    }

    /*
    public static synchronized Singleton getInstance() {//实现同步
        if (obj == null) obj = new Singleton();
        return obj;
    }
    */

    public static Singleton getInstance(){
        if (obj == null){
            synchronized (Singleton.class){
                if (obj==null){
                    obj = new Singleton();
                }
            }
        }
        return obj;
    }
}
